﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;



namespace Homework6
{
    public partial class Form1 : Form
    {
        String file1, file2, path1, path2;
        static String origin_path = "D:\\C# work\\Homework6\\Homework6";

        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            file1 = button2.Text;
            label3.Text = file1;
            path1 = Path.Combine(origin_path, file1);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            file1 = button3.Text;
            label3.Text = file1;
            path1 = Path.Combine(origin_path, file1);


        }

        private void button4_Click(object sender, EventArgs e)
        {
            file2 = button4.Text;
            label3.Text = file2;
            path2 = Path.Combine(origin_path, file2);


        }

        private void button5_Click(object sender, EventArgs e)
        {
            file2 = button5.Text;
            label3.Text = file2;
            path2 = Path.Combine(origin_path, file2);


        }

        private void button6_Click(object sender, EventArgs e)
        {
            file2 = button6.Text;
            label3.Text = file2;
            path2 = Path.Combine(origin_path, file2);


        }

        private void Form1_Click(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {

            FileStream fin1 = new FileStream(path1,
            FileMode.Open, FileAccess.Read);
            FileStream fin2 = new FileStream(path2,
            FileMode.Open, FileAccess.Read);

            String path_destination = Path.Combine(origin_path, "data");
            if (!Directory.Exists(path_destination)){
                Directory.CreateDirectory(path_destination);
            }
            String txt_path = Path.Combine(path_destination, "newfile.txt");

            FileStream fout = new FileStream(txt_path,
            FileMode.Create, FileAccess.Write);

            StreamReader brin1 = new StreamReader(fin1, System.Text.Encoding.Default);
            StreamReader brin2 = new StreamReader(fin2, System.Text.Encoding.Default);
            StreamWriter brout = new StreamWriter(fout, System.Text.Encoding.Default);
           
            for (string s = brin1.ReadLine(); s != null; s = brin1.ReadLine())
            {
                
                brout.WriteLine(s);
                Console.WriteLine(s);
                

            }
            
            for (string s = brin2.ReadLine(); s != null; s = brin2.ReadLine())
            {
                
                brout.WriteLine(s);
                Console.WriteLine(s);
                
            }
            label3.Text = "新文件已生成";
            brin1.Close();
            brin2.Close();
            brout.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            file1 = button1.Text;
            label3.Text = file1;
            path1 = Path.Combine(origin_path, file1);


        }
    }
}
